﻿<?php
// ------------------------------------------------------------------
// NEEDED STUBS FOR THIS EXAMPLE
// ------------------------------------------------------------------


// this will include all needed files to be able to build a Request
include_once($CONF["STUBS_FOLDER"]."Map24Geocoder51/Map24Geocoder51.php5");


// ------------------------------------------------------------------
// NEEDED PARAMETERS FOR THIS REQUEST
// ------------------------------------------------------------------

// the address to geocode

$country = "de";
$city = "Eschborn";
$street = "Düsseldorfer";

// the number of alternatives to display
$maxNoOfAlternatives = 10;


// ------------------------------------------------------------------
// BUILDING THE REQUEST
// ------------------------------------------------------------------


// definition of the request header with Map24ID and SessionID
$header = new RequestHeader();
$header->Map24ID  = $CONF['MAP24_ID'];
$header->ClientID = $CONF['SESSION_ID'];

// definition of the request body
$request = new MapSearchQualifiedRequest();

//Write the Array of Properties

if(isset($country)) {
	$objIdx=0;
	$searchProperty[$objIdx]= new Property();
	$searchProperty[$objIdx]->Key = "CTRY";
	$searchProperty[$objIdx]->Value = $country;
}
if(isset($city)) {
	$objIdx++;
	$searchProperty[$objIdx]= new Property();
	$searchProperty[$objIdx]->Key = "CITY";
	$searchProperty[$objIdx]->Value = $city;
}
if(isset($street)) {
	$objIdx++;
	$searchProperty[$objIdx]= new Property();
	$searchProperty[$objIdx]->Value = "STREET";
	$searchProperty[$objIdx]->Value = $street;
}

// Check, if there are at least one Property to search for
if($objIdx==0) {
	$resultString = "Please enter at least one Property";
}
// everythink is okay ;o)
else {

	$request->SearchProperties = $searchProperty;
	$request->MaxNoOfAlternatives = $maxNoOfAlternatives;
	$request->Options=array("Crossings","Housenumbers");

// ------------------------------------------------------------------
// EXECUTE THE REQUEST
// ------------------------------------------------------------------


// in this object the SoapClient will be initiated and executed
	$geocoder = new Map24Geocoder51($CONF['MAPTP_SYSTEM'],$CONF['MAP24_ID'],$CONF['SESSION_ID']);

	$response = $geocoder->SearchQualified($header,$request);


// ------------------------------------------------------------------
// OUTPUT THE RESULT
// ------------------------------------------------------------------


	if(isset($response->Alternatives) && count($response->Alternatives) > 0)
	{
		foreach ($response->Alternatives as $result)
		{
			$counter++;
			$resultString .= "<div>".$counter.". ";

			foreach ($result->PropertiesMajor as $property)
			{
				$resultString .= $property->Value." ";
			}
			$resultString .= "</div>";
		}
	}
	else
	{
		$resultString = "no results found for $country, $city, $street";
	}
}

?>